<%@page import="org.wabson.alfresco.translations.bean.Jarfile"%>
<%@page import="org.wabson.alfresco.translations.bean.JarListLoader"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.Iterator" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.Collections"%>
<%@page import="java.util.List"%>
<%@page import="org.wabson.alfresco.translations.BlobInfoDateComparator" %>
<%@page import="org.wabson.alfresco.translations.bean.PackageCollection"%>
<%@page import="org.wabson.alfresco.translations.bean.BundlePackage"%>
<%@page import="org.wabson.alfresco.translations.bean.Version"%>
<%@page import="org.wabson.alfresco.translations.bean.VersionCollection"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%
   WebApplicationContext springContext = WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServletContext());
   
   List<Jarfile> uploads = ((JarListLoader) springContext.getBean("jar-list-loader")).getJars();
   
   VersionCollection vc = (VersionCollection) springContext.getBean("alfresco-versions");
   List<Version> versions = vc.getVersions();

   PackageCollection pc = (PackageCollection) springContext.getBean("alfresco-packages");
   List<BundlePackage> packages = pc.getPackages();
%>
<html>
<head>
<title>Alfresco I18N Tools</title>
<link rel="stylesheet" type="text/css" href="/assets/screen.css" />
<script type="text/javascript">
function completeForm(thisform)
{
	var p = thisform.elements["p"].value;
	var v = thisform.elements["v"].value;
	var ce = v.indexOf("community") == 0 ? "community" : v.indexOf("enterprise") == 0 ? "enterprise" : "";
	var version = v.substring(v.indexOf("-") + 1);
	var j = "alfresco-" + ce + "-" + (p != "" ? p + "-" : "") + "messages-" + version + ".jar";
	thisform.elements["j"].value = j;
	location.href = location.protocol + "//" + location.host + "/details?j=" + j;
	return false;
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-340797-7']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>
</head>
<body>
<div class="header">
<h1 class="title"><a href="/">Alfresco I18N Tools</a></h1>
</div>

<div class="body">
<p>Alfresco I18N Tools is a set of tools to assist translators in developing language packs for Alfresco. Using this site you can upload a translation to test it for completeness or see what has changed between different Alfresco releases.</p>
<h2>Recent Uploads</h2>
<p>Recently uploaded translation packages.</p>
<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Uploaded</th>
</tr>
<%
   for(Jarfile jar : (uploads.size() > 5 ? uploads.subList(0, 5) : uploads))
   {
%>
<tr>
<td><a href="/details?k=<%= jar.getId() %>"><%= jar.getName() %></a></td>
<td><%= NumberFormat.getInstance().format(jar.getSize() / 1024) %>kB</td>
<td><%= DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(jar.getCreationDate()) %></td>
</tr>
<%
   }
%>
</table>
<p><a href="/all-uploads">All Uploads</a><%-- | <a href="upload.jsp">Upload Translation</a>--%></p>

<h2>Alfresco Message Bundles</h2>
<p>Browse the base Alfresco packages.</p>
<form action="/details" method="get" onsubmit="return completeForm(this);">
<div class="form-field">
View details for package <select id="package" name="p">
<%
for (BundlePackage p : packages)
{
%>
<option value="<%=p.getName()%>"><%=p.getTitle()%></option>
<%
}
%>
</select>, version
<select id="version" name="v">
<%
for (Version version : versions)
{
%>
<option value="<%=version.getName()%>"><%=version.getTitle()%></option>
<%
}
%>
</select>

</div>
<div class="form-field">
<input type="hidden" name="j" value="">
<input type="submit" value="Details">
</div>
</form>


<h2>Message Bundle Changes</h2>
<p>Find out what message bundles have changed between Alfresco versions</p>
<form action="/changes" method="get">
<div class="form-field">
Compare <select id="baseVersion" name="b">
<%
for (Version version : versions)
{
%>
<option value="<%=version.getName()%>"><%=version.getTitle()%></option>
<%
}
%>
</select> with <select id="compareVersion" name="c">
<%
for (Version version : versions)
{
%>
<option value="<%=version.getName()%>"><%=version.getTitle()%></option>
<%
}
%>
</select>, package <select id="package" name="p">
<%
for (BundlePackage p : packages)
{
%>
<option value="<%=p.getName()%>"><%=p.getTitle()%></option>
<%
}
%>
</select>
<span class="form-help"></span></div>
<div class="form-field">
<input type="submit" value="Compare">
</div>
</form>
</div>
<div class="footer">
<p>Alfresco I18N Tools, developed by <a href="http://twitter.com/wabson">@wabson</a></p>
</div>
</body>
</html>